<?php
session_start();
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../model/Util/Tool.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../model/Util/Pager.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../model/Service/ArticleService.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../model/Context/BaseContext.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../model/ServiceResult/ServiceResult.php';
// set timeout period in seconds
$inactive = 3800;
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) )
{
	$session_life = time() - $_SESSION['timeout'];
	if($session_life > $inactive)
	{
		session_destroy();
		$gotoPage = Tool::curPageURL();
		$_SESSION['gotoPage'] = $gotoPage;
		header("Location: index.php?type=l&action=logout");
	}
}
$_SESSION['timeout'] = time();
$smarty = new Smarty();
$smarty->setTemplateDir(__DIR__.DIRECTORY_SEPARATOR . '../templates');
$smarty->setCompileDir(__DIR__.DIRECTORY_SEPARATOR . '../templates_c');
$templateDir = $smarty->getTemplateDir(0);



if (!file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'../../_config/setting/setting.ini'))
{
	echo "Configuration file not found!";
}
else
{
	// include class
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../../plugin/Config/Config.php';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
$context = new BaseContext();
$result = new ServiceResult();
$smarty->assign('templateDir',$glb["websiteURL"]."/admin/templates");
$smarty->assign('websiteURL',$glb["websiteURL"]);
$smarty->assign('get',$_GET);
$smarty->display($templateDir . "/header/head.tpl");
?>
</head>
<body>
<?php
if(!isset($_GET['func']))
{
	header("Location:index.php?func=dash");
}
if(isset($_GET['func']) && $_GET['func']=="login")
{
	if(isset($_SESSION['member']))
	{
		header("Location:index.php?func=dash");
	}
	if(isset($_GET['opt']))
	{
		$opt = $_GET['opt'];
		if($opt == "pass")
		{
			$smarty->display($templateDir . "/temp1/forgotPass.tpl");
		}
		if($opt == "resetPassword" && isset($_GET['token']))
		{
			$token = $_GET['token'];
			$smarty->assign("token",$token);
			$smarty->display($templateDir . "/temp1/newPass.tpl");
		}
	}
	else
	$smarty->display($templateDir . "/login/login.tpl");
}
else
{
	if(!isset($_SESSION['member']))
	{
		$gotoPage = Tool::curPageURL();
		$_SESSION['gotoPage'] = $gotoPage;
		header("Location:index.php?func=login");
		die();
	}
	?>
	<!-- Themer -->  
	<?php 
		$smarty->display($templateDir . "/themer/themer.tpl");
	?>
    <!-- Themer End -->
    

	<!-- Header Wrapper -->
	<?php
		$smarty->assign("SESSION",$_SESSION);
		$smarty->display($templateDir . "/header/header.tpl");
	?>
    
    <!-- Main Wrapper -->
    <div id="mws-wrapper">
    	<!-- Necessary markup, do not remove -->
		<div id="mws-sidebar-stitch"></div>
		<div id="mws-sidebar-bg"></div>
        
        <!-- Sidebar Wrapper -->
        <div id="mws-sidebar">
        	
            <!-- Main Navigation -->
            <?php
				$smarty->display($templateDir . "/sidebar/sidebar.tpl");
			?>
            <!-- End Navigation -->
            
        </div>
        
        
        <!-- Container Wrapper -->
        <div id="mws-container" class="clearfix">
        
        	<!-- Main Container -->
            <div class="container">
            <?php 
				if(isset($_GET['func']))
				{
					$func = $_GET['func'];
					if($func == "article")
					{
						include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'/home/article.php';
					}
				}
				if(isset($_GET['func']))
				{
					$func = $_GET['func'];
					if($func == "cate")
					{
						include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'/home/cate.php';
					}
				}
            ?>
            </div>
            <!-- End Main Container -->
            
            <!-- Footer -->
            <div id="mws-footer">
            	Copyright BArt Shop 2012. All Rights Reserved.
            </div>
            <!-- End Footer -->
            
        </div>
        <!-- End Container Wrapper -->
        
    </div>
    <!-- End Main Wrapper -->
	<?php }?>
</body>
</html>
